#!/bin/bash

# 确保JSON解析器jq已安装
# if ! command -v jq &> /dev/null
# then
#     echo "jq could not be found. Please install it first."
#     exit 1
# fi

# 定义json文件路径
json_file="git.json"

# 使用jq读取json文件中的url和topath字段
jq -r '.[] | "\(.url) \(.path) \(.type)"' "$json_file" |
while read -r url path type; do
#     git clone "$url" "$path"

    if test "git" = "$type"; then
        echo "$type"
        #git submodule add "$url" "$path"
        git config -f .gitmodules submodule."$path".path "$path"
        git config -f .gitmodules submodule."$path".url "$url"
        git config --add submodule."$path".path "$path"
        git config --add submodule."$path".url "$url"
    fi
    if test "file" = "$type"; then
        echo "$type"."$url"
        #aria2c -o "./"."$path" "$url"
    fi
done
